#include <iostream>

using namespace std;

typedef long long LL;
LL n, a, b;

LL gcd(LL a, LL b)
{
    return b == 0 ? a : gcd(b, a % b);
}

LL lcm(LL a, LL b)
{
    return a * b / gcd(a, b);
}

int main()
{
    int T; cin >> T;
    while(T--)
    {
        cin >> n >> a >> b;
        int ret = n / a + n / b;
        ret -= n / lcm(a, b);
        cout << ret << endl;
    }
    return 0;
}
